/*------------------------------------------------------------------------*/
/* Sample code of OS dependent controls for FatFs                         */
/* (C)ChaN, 2012                                                          */
/*------------------------------------------------------------------------*/

#include <stdlib.h>		/* ANSI memory controls */
#include <malloc.h>		/* ANSI memory controls */

#include "ff.h"


#if _FS_REENTRANT

int ff_cre_syncobj(BYTE _vol, _SYNC_t *_sobj)
{
	int _ret;
	static _SYNC_t _sem[_VOLUMES];	/* FreeRTOS */

	if (!_sem[_vol])					/* FreeRTOS */
		vSemaphoreCreateBinary(_sem[_vol]);
	
	*_sobj = _sem[_vol];
	_ret = (*_sobj != NULL);

	return _ret;
}


int ff_del_syncobj(_SYNC_t _sobj)
{
	int _ret;

	_ret = 1;					/* FreeRTOS (nothing to do) */

	return _ret;
}

int ff_req_grant(_SYNC_t _sobj)
{
	int _ret;

	_ret = (xSemaphoreTake(_sobj, _FS_TIMEOUT) == pdTRUE);	/* FreeRTOS */

	return _ret;
}


void ff_rel_grant(_SYNC_t _sobj)
{
	xSemaphoreGive(_sobj);	/* FreeRTOS */
}

#endif




#if _USE_LFN == 3	/* LFN with a working buffer on the heap */


void *ff_memalloc(UINT _msize)
{
	return malloc(_msize);
}

void ff_memfree(void *_mblock)
{
	free(_mblock);
}

#endif
